package com.lz.ovuola.service.assembler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lz.ovuola.entity.PhysiologicalReferencevDataDo;
import com.lz.ovuola.service.dto.ReferencevDataDto;
import com.lz.ovuola.service.impl.PhysiologicalConst;
import com.lz.ovuola.util.exception.BusinessException;
import com.lz.ovuola.util.exception.msg.CommonMsgEnum;
import com.lz.ovuola.util.threadlocal.UserContextHolder;

/**
 * 包装工具
 * 
 * @author fz
 *
 */
public class ReferencevDataAssembler implements Assembler<ReferencevDataDto> {

	private Logger logger = LoggerFactory.getLogger("ReferencevDataAssembler");
	private static final ReferencevDataAssembler ASSEMBLER = new ReferencevDataAssembler();

	private ReferencevDataAssembler() {
		super();
	}

	public static ReferencevDataAssembler getAssembler() {
		return ASSEMBLER;
	}

	@Override
	public ReferencevDataDto toDto(Object object) throws BusinessException {
		if (object instanceof PhysiologicalReferencevDataDo) {
			PhysiologicalReferencevDataDo physiologicalReferencevDataDo = (PhysiologicalReferencevDataDo) object;
			ReferencevDataDto dataDto = new ReferencevDataDto();
			dataDto.setReferenceValue(physiologicalReferencevDataDo
					.getReferenceValue());
			dataDto.setThreshold(PhysiologicalConst.THRE_SHOLD);
			// dataDto.setThreshold(dataDto.getThreshold());
			dataDto.setCreateTime(physiologicalReferencevDataDo.getCreateTime());
			return dataDto;
		} else {
			logger.error(
					"---用户id：{},PhysiologicalReferencevDataDo转ReferencevDataDto过程中出现异常",
					UserContextHolder.get().getUserId());
			throw new BusinessException(
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getStatus(),
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getMsg());
		}
	}
}
